package br.ufrj.dcc.smarthotel.activities;

import java.util.Date;

import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.Spinner;
import br.ufrj.dcc.smarthotel.R;
import br.ufrj.dcc.smarthotel.controls.SignUpControl;
import br.ufrj.dcc.smarthotel.listeners.SignupSendClickListener;

public class SignUpActivity extends AppActivity {
	private EditText txtName;
	private EditText txtEmail;
	private EditText txtPassword;
	private EditText txtConfirmPassword;
	private DatePicker dateBirthDate;
	private EditText txtPhone;
	private Spinner spinnerIdType;
	private EditText txtId; 
	private Button btnSubmit;
	private SignUpControl signUpControl;
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.usersignup);
        
        this.signUpControl = new SignUpControl(this);
        
        this.findAllViews();
        
        this.fillIdentificationTypeSpinner();
        
        SignupSendClickListener signupListener = new SignupSendClickListener(this);
        
        this.btnSubmit.setOnClickListener(signupListener);
    }
    
    public void SignUp() {
    	this.signUpControl.SignUp();
    }
    
    private void findAllViews() {
    	this.txtName = (EditText) findViewById(R.id.txtName);
    	this.txtEmail = (EditText) findViewById(R.id.txtEmail);
    	this.txtPassword = (EditText) findViewById(R.id.txtPassword);
    	this.txtConfirmPassword = (EditText) findViewById(R.id.txtConfirmPassword);
    	this.dateBirthDate = (DatePicker) findViewById(R.id.dateBirthDate);
    	this.txtPhone = (EditText) findViewById(R.id.txtPhone);
    	this.spinnerIdType = (Spinner) findViewById(R.id.spinnerIdType);
    	this.txtId = (EditText) findViewById(R.id.txtId);
    	this.btnSubmit = (Button) findViewById(R.id.btnSubmit);
    }
    
    private void fillIdentificationTypeSpinner() {
    	ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.IdTypes, android.R.layout.simple_spinner_item);
    	
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        
        this.spinnerIdType.setAdapter(adapter);
    }

	public String getName() {
		return txtName.getText().toString().trim();
	}

	public String getEmail() {
		return txtEmail.getText().toString().trim();
	}

	public String getPassword() {
		return txtPassword.getText().toString().trim();
	}
	
	public String getConfirmPassword() {
		return txtConfirmPassword.getText().toString().trim();
	}

	public Date getBirthDate() {
		return new Date(dateBirthDate.getYear() - 1900, dateBirthDate.getMonth(), dateBirthDate.getDayOfMonth());
	}

	public String getPhone() {
		return txtPhone.getText().toString().trim();
	}

	public String getIdentificationType() {
		return spinnerIdType.getSelectedItem().toString().trim();
	}

	public String getIdentification() {
		return txtId.getText().toString().trim();
	}
}